package com.example.config;

import com.example.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-07-26
 * Time: 15:51
 */
@ResponseBody
@ControllerAdvice
//@RestControllerAdvice
public class ExceptionAdvice {

    /**
     * 用来对没有处理的异常进行统一处理
     * @param e
     * @return
     */
    @ExceptionHandler
    public Result handlerException(Exception e){
        return Result.fail((e.getMessage()));
    }
    @ExceptionHandler
    public Result handlerException(NullPointerException e){
        return Result.fail("发生NullPointerException异常"+e.getMessage());
    }
    @ExceptionHandler
    public Result handlerException(ArithmeticException e){
        return Result.fail("发生ArithmeticException异常"+e.getMessage());
    }
}
